<template>
	<div style="position: relative;">
		<Row>
	        <Col span="24"  style="text-align: center;">
	            <Card style="width:880px;margin: auto;">
	                <p slot="title"><slot></slot></p>
	                <Row >
				        <Col span="8" >
				        	<span>年级：</span>
				            <Select v-model="importgradeid"  disabled style="width:200px">
				                <Option v-for="item in importgradelist" :value="item.value" :key="item.value">{{ item.label }}</Option>
				            </Select>
				        </Col>
				        <Col span="8" >
				        	<span>段长：</span>
				            <Select v-model="yearsegment" filterable placeholder="输入快速匹配" style="width:200px">
				                <Option v-for="item in yearsegmentlist" :value="item.value" :key="item.value">{{ item.label }}</Option>
				            </Select>
				        </Col>
				        <Col span="8" >
				        	<span>职称：</span>
							<Input v-model="jobTitle" placeholder="请输入职称" style="width:200px"></Input>
				        </Col>
				    </Row>
	                
				    <Row>
				    	<Col span="24" style="margin-top:15px">
				    		<Button type="ghost" @click="chance" icon="close-round">取消</Button>
				    		<Button type="primary" @click="saveyearsegment" icon="checkmark-round">保存</Button>
				    	</Col>
				    </Row> 
				    
	            </Card>
	        </Col>
	    </Row>
	     <Spin size="large" fix v-if="loadingShow"></Spin>
	</div>
</template>

<script>
	import api from "@/components/js/Apidomain.js"
	
	export default{
		props:{
			importgradeid:"",
			importgradelist: {
		        type: Array,
		        default: function () {return []}
		   },
		},
		data(){
			return{
				loadingShow:false,			//控制面板的加载中的显示和隐藏
				
				jobTitle:"",				//新增年段长的职称
				yearsegment:"",				//选择的年段长id
				
				yearsegmentlist:[
//                  {value: '1',label: 'New York'},
//                  {value: '2',label: 'London'},
//                  {value: '3',label: 'Sydney'},
                ],
			}
		},
		created(){
			this.getallteacherlist();
		},
		methods:{
			chance:function(){
				this.$emit('chance')
			},
			getallteacherlist:function(){
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/getTchTeacherSelectList';
            	this.$http.post(url,{}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.yearsegmentlist = response.data.data
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00019',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			},
			saveyearsegment:function(){
				if(this.importgradeid == "" || this.yearsegment == "" || this.jobTitle == ""){
					self.$Message.error({
								content: "请完善信息后再提交",
								duration: 10,
								closable: true
							});	
					return;
				}
				var senddata = {
					"id": "",  
					"gradeId": this.importgradeid,
					"teacherId": this.yearsegment, 
					"jobTitle": this.jobTitle 
				}
//				//console.log(senddata)
				this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/tchTeacher/addGradeLeader';
            	this.$http.post(url,senddata).then(function(response) {
					if(response.data.success == true){
						self.$Message.success({
		                    content: '保存成功',
		                    duration: 10,
		                    closable: true
               			})
						self.$emit('chance')
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00020',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
			}
		}
	}
</script>

<style>
</style>